package com.teamwings.modules.file.feign;

import com.teamwings.common.vo.Result;
import com.teamwings.modules.file.factory.FileFallbackFactory;
import feign.Response;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;

@FeignClient(
        value = "upload-file-service",
        url = "http://127.0.0.1:8089/",
        fallbackFactory = FileFallbackFactory.class
)
@Component
public interface FileServiceFeign {

    @PostMapping(value = "/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    Result<?> uploadFile(
            @RequestParam("userName") String userName,
            @RequestParam("savePath") String savePath,
            @RequestParam("fileName") String fileName,
            @RequestPart(value = "userFile") MultipartFile multipartFile
    );

    /**
     * 移动目录
     * 用于把临时目录调整为正式目录
     */
    @PostMapping("/moveFile")
    Result<?> moveFile(
            @RequestParam("source") String strSource,
            @RequestParam("target") String strTarget
    );

    /**
     * 三水民政局删除图片
     */
    @PostMapping("/delFj")
    Result<?> delFj(
            @RequestParam("userName") String userName,
            @RequestParam("savePath") String savePath,
            @RequestParam("fileName") String fileName
    );

    /**
     * 下载单个文件
     */
    @RequestMapping("/downloadFile")
    Response downLoadFile(
            @RequestParam("userName") String userName,
            @RequestParam("savePath") String savePath
    );

    // 2021-03-30
    // 添加批量下载
    @RequestMapping("/downloadFiles")
    Response downLoadFiles(
            HttpServletResponse response,
            @RequestParam("paths") String paths
    ) throws UnsupportedEncodingException;


    /**
     * 保存关联，把文件复制到指定文件夹，用于审批表关联文件
     */
    @RequestMapping("/copyFileToFileSp")
    Result<?> copyFileToFileSp(
            @RequestParam("userName") String userName,
            @RequestParam("sourceFile") String sourceFile,
            @RequestParam("targetFile") String targetFile
    );
}
